Imports System.Data
Partial Class Client_frmSubCatWiseProduct
    Inherits System.Web.UI.Page
    Dim _BO As New Bo
    Dim dt As New DataTable
    Dim _SubCategoryId As String
    Dim cntProduct As Integer
    Dim row, i As Integer
    Dim dt1Table As New DataTable
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _SubCategoryId = Request.QueryString("SubCategoryId")
        If _SubCategoryId = "" Then
            Response.Redirect("frmDataList.aspx")
        Else
            dt = _BO.getSubCatWiseProduct(ViewState("min"), ViewState("max"), _SubCategoryId)
            DataList.DataSource = dt
            DataList.DataBind()
        End If
        lnkNext.Enabled = False
        If Not IsPostBack Then
            ViewState("min") = 1
            ViewState("max") = 8
            dt1Table = _BO.getSubCatWiseProduct(ViewState("min"), ViewState("max"), _SubCategoryId)
            DataList.DataSource = dt1Table
            DataList.DataBind()
            cntProduct = _BO.counttotSubCatProduct(_SubCategoryId)
            If ViewState("min") <= 1 Then
                lnkPrevious.Enabled = False
            End If
            If ViewState("max") < cntProduct Then
                lnkNext.Enabled = True
            End If
        End If
    End Sub

    Protected Sub lnkPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkPrevious.Click
        _BO.getSubCatWiseProduct(ViewState("min"), ViewState("max"), _SubCategoryId).Rows.Clear()
        cntProduct = _BO.counttotSubCatProduct(_SubCategoryId)
        ViewState("min") = Val(ViewState("min")) - 8
        ViewState("max") = Val(ViewState("max")) - 8
        DataList.DataSource = _BO.getSubCatWiseProduct(ViewState("min"), ViewState("max"), _SubCategoryId)
        DataList.DataBind()
        If ViewState("min") <= 1 Then
            lnkPrevious.Enabled = False
        End If
        If ViewState("max") <= cntProduct Then
            lnkNext.Enabled = True
        End If
    End Sub

    Protected Sub lnkNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkNext.Click
        _BO.getSubCatWiseProduct(ViewState("min"), ViewState("max"), _SubCategoryId).Rows.Clear()
        cntProduct = _BO.counttotSubCatProduct(_SubCategoryId)
        ViewState("min") = Val(ViewState("min")) + 8
        ViewState("max") = Val(ViewState("max")) + 8
        DataList.DataSource = _BO.getSubCatWiseProduct(ViewState("min"), ViewState("max"), _SubCategoryId)
        DataList.DataBind()
        If ViewState("max") > cntProduct Then
            lnkNext.Enabled = False
        End If
        If ViewState("min") > 1 Then
            lnkPrevious.Enabled = True
        End If
    End Sub
End Class
